package cn.edu.jxau.test;

import java.util.Objects;
import java.util.concurrent.ExecutionException;

import cn.edu.jxau.util.LinkedQueue;
import cn.edu.jxau.util.Queue;

public class Main {

	public static void main(String[] args) throws InterruptedException, ExecutionException {

		Node<Integer> root = new Node<>(8);
		root.left = new Node<>(6);
		root.right = new Node<>(10);
		root.left.left = new Node<>(5);
		root.left.right = new Node<>(7);
		root.right.left = new Node<>(9);
		root.right.right = new Node<>(11);
		levelOrder(root);
	}

	public static <T> void levelOrder(Node<T> root) {

		Objects.requireNonNull(root, "参数root不能为null");
		Queue<Node<T>> queue = new LinkedQueue<>();
		queue.enqueue(root);
		while (!queue.isEmpty()) {
			Node<T> n = queue.dequeue();
			if (n == null) {
				continue;
			}
			queue.enqueue(n.left);
			queue.enqueue(n.right);
			System.out.print(n.data + "\t");
		}
	}
}

class Node<T> {

	public T data;
	public Node<T> right;
	public Node<T> left;

	public Node(T data) {
		this.data = data;
	}
}